"""
des: 自定义控件
author: mr52hz
date: 2024-04-17
"""
from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtWidgets import QLabel


class ClickLabel(QLabel):

    onClicked = pyqtSignal(object)

    def __init__(self, parent=None):
        super().__init__(parent)
        self.pressed = 0

    def mousePressEvent(self, event):
        self.pressed = 1

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton and self.pressed == 1:
            self.pressed = 0
            self.onClicked.emit(self.objectName())   # type: ignore

    def updateStyle(self):
        self.style().unpolish(self)
        self.style().polish(self)
        self.update()
